;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Report.Dyutaskreport", [])
        .controller("DyutaskreportCtrl", ["$scope", "ybWidget", "ybHttp", "MESG_TYPE", "UserContextService", "$timeout", "$filter", function ($scope, ybWidget, ybHttp, MESG_TYPE, UserContextService, $timeout, $filter) {
            // 高级搜索的展示与隐藏
            $scope.toolbarConfig = {};

            // 切换高级搜索展示与隐藏
            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                    return;
                }
                $timeout(function () {
                    $scope.toolbarConfig["show" + toolbar] = true;
                });
            };

            $scope.exportParam = {
                allUrl: ybHttp.RequestUrl("device", "/tdyutask/exportReport")
            };


            // 列表查询条件
            $scope.condition = {
            };
            // 表格信息
            $scope.tbConf = {
                firstTableCol: [
                    {
                        name: '代理商',
                        dataField: 'dealerName',
                        width: 120,
                        rowSpan: 2
                    },
                    {
                        name: '服务代表',
                        dataField: 'service',
                        width: 120,
                        rowSpan: 2
                    },
                    {
                        name: '销售完成情况',
                        width: 360,
                        colSpan: 3
                    },
                ],
                secondTableCol: [
                    {
                        name: '任务（万元）',
                        dataField: 'taskNum',
                        width: 120,
                    },
                    {
                        name: '已完成（万元）',
                        dataField: 'completeNum',
                        width: 120,
                    },
                    {
                        name: '累计完成率',
                        dataField: 'completedRate',
                        width: 120,
                    },
                ]
            };

            // 分页信息
            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.checkDate = function () {
                $scope.condition.year = $scope.condition.yearShow.getFullYear()
            };
            $scope.dataList = [];
            $scope.search = function (curPage) {
                if (curPage) $scope.pageInfo.curPage = curPage;
                getDataList();
            };

            function getDataList() {
                var url = "/tdyutask/list4Report";
                var param = {
                    year: $scope.condition.year,
                    month: $scope.condition.month
                };
                if (!$scope.condition.year || !$scope.condition.month) {
                    ybWidget.ShowMessage('请选择年和月后再查询', MESG_TYPE.Error);
                    return;
                }
                ybHttp.Post('device', url, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    resp.value.forEach(i => {
                         if (i.dealerName.includes('区域')) {
                            i.rowColor = true
                         }else {
                            i.rowColor = false
                         }
                    });
                    $scope.dataList = resp.value;
                });
            }

            $scope.reset = function () {
                $scope.condition = {
                };
            };


            // 初始化页面信息
            (function () {
                // getDataList();
            })()
        }])
        ;
})(window, window.angular);